package jermedit.gobjekte;

import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;



public class Relationship extends LineObject {

     // 1:* ; 1:1 usw 
    
    public Relationship(int vonX, int vonY, int nachX, int nachY){
        super(vonX,vonY,nachX,nachY);
        
    }
    
    public void drawSubStroke(Graphics2D g2){
        //Dummy?
    }
    
    @Override
    public void drawSub(Graphics2D g2) {
        g2.draw(new Line2D.Double(this.getVonX(),this.getVonY(),this.getNachX(),this.getNachY()));
        // Muss die richtigen x- und y-Punkte für den String durchlaufen                 
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);       
                // Koordinatensystem drehen
        AffineTransform neu = g2.getTransform();
        AffineTransform alt = (AffineTransform)neu.clone();
        neu.translate((this.getVonX() + this.getNachX()) / 2, (this.getNachY() + this.getVonY()) / 2);
        neu.rotate(Math.atan((1.0 * this.getNachY() - this.getVonY()) / (this.getNachX() - this.getVonX())));
        g2.setTransform(neu);

        // Text einzeichnen
        FontMetrics f = g2.getFontMetrics();
        g2.drawString(this.getRelation(), -f.stringWidth(this.getRelation()) / 2, -2);
        g2.drawString(this.getName(), -f.stringWidth(this.getName()) / 2, 10);
       // g2.drawString("TEST", -f.stringWidth("TEST") / 2, -2);
        
        // Koordinatensystem zurücksetzen
        g2.setTransform(alt);
    }
/*    
    public String getName() {
        return this.getName();
    }

    public void setName(String name) {
        this.setName(name);
    }

    public String getRelation() {
        return relation;
    }

    public void setRelation(String relation) {
        this.relation = relation;
    }
    
    public void rename(String name) {
        this.setName(name);
    }
    
    public void renameRel(String relation) {
        this.setRelation(relation);
    }
*/    
     public void textlinie(Graphics2D g, String s, int x1, int y1, int x2,
            int y2)
    {

        // Koordinatensystem drehen
        AffineTransform alt = g.getTransform(); 
        AffineTransform neu = new AffineTransform();
        neu.translate((x1 + x2) / 2, (y2 + y1) / 2);
        neu.rotate(Math.atan((1.0 * y2 - y1) / (x2 - x1)));
        g.setTransform(neu);

        // Text einzeichnen
        FontMetrics f = g.getFontMetrics();
        g.drawString(s, -f.stringWidth(s) / 2, -2);

        // Koordinatensystem zurücksetzen
        g.setTransform(alt);
    }
     
}
